package com.qyhl.webtv.module_live.teletext.content;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.live.TeleTextLiveBean;
import com.qyhl.webtv.module_live.common.LiveUrl;

import java.util.List;

/**
 * Created by qyhl on 2017/7/7.
 */

public class TeleTextLiveModel implements TeleTextLiveContract.TeleTextLiveModel {
    private TeleTextLiveContract.TeleTextLivePresenter mPresenter;

    public TeleTextLiveModel(TeleTextLiveContract.TeleTextLivePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getDatas(String sceneId, String contentId, final boolean isMore) {

        EasyHttp.get(LiveUrl.GET_TELETEXT_CONTENT)
                .params("sceneId", sceneId)
                .params("contentId", contentId)
                .execute(new SimpleCallBack<List<TeleTextLiveBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            if (isMore) {
                                mPresenter.setNoMore("没有更多内容了！");
                            } else {
                                mPresenter.setError(0, "暂无任何数据，点击刷新试试看！");
                            }
                        } else {
                            if (isMore) {
                                mPresenter.setError(-2, "无法获取更多！");
                            } else {
                                mPresenter.setError(2, "数据异常，点击重新加载！");
                            }
                        }
                    }

                    @Override
                    public void onSuccess(List<TeleTextLiveBean> teleTextLiveBeans) {
                        if (isMore) {
                            mPresenter.setDatas(teleTextLiveBeans, true);
                        } else {
                            mPresenter.setDatas(teleTextLiveBeans, false);
                        }
                    }
                });


    }

}
